package liming.ai.abstracts;

import liming.tool.json.annotation.JsonMark;
import liming.tool.json.annotation.JsonMarkCollection;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class MessageContext {
    @JsonMark
    @JsonMarkCollection(AbstractMessage.class)
    List<AbstractMessage> messages=new ArrayList<>();

    public void addMessage(AbstractMessage message){
        messages.add(message);
    }

    public List<JSONObject> getMessages(){
        List<JSONObject> objects = new ArrayList<>();
        for (AbstractMessage message : messages)
            objects.add(message.serializeBody(message.getDefaultClass()));
        return objects;
    }
    public boolean removeLastMessage(){
        if (messages.isEmpty())
            return false;
        messages.remove(messages.size()-1);
        return true;
    }
}
